package com.base.action;

import java.util.List;

import com.base.service.MenuService;
import com.base.service.PermissionService;
import com.base.service.PersonnelService;
import com.base.service.RuleService;
import com.common.bean.Menuctrl;
import com.common.bean.Menuinfo;
import com.common.bean.Personnel;
import com.common.bean.Personneltorulelink;
import com.common.bean.Rule;
import com.core.ssh2.AbstractActionSupport;

public class PermissionAction extends AbstractActionSupport {

	private static final long serialVersionUID = -6203642073423740229L;
	
	private PermissionService permissionService;
	
	private PersonnelService personnelService;
	
	private MenuService menuService;
	
	private RuleService ruleService;
	
	private String principalType;//a string value of rule or personnel is required.
	
	private long ruleno;
	
	private String staffcode;
	
	private Rule rule;
	
	private Personnel personnel;
	
	private List<Menuinfo> menulist;
	
	private List<Rule> rulelist;
	
	private List<Menuctrl> ruleMenus;
	
	private List<Personneltorulelink> personnelRules;
	
	@Override
	public String execute() throws Exception {
		if("rule".equals(principalType)&ruleno != 0) {//为角色分配菜单权限
			rule = ruleService.findRule(ruleno);
			menulist = menuService.findAllMenuinfo();
			//ruleMenus = permissionService.findAllMenuctrl();
		} else if("personnel".equals(principalType)) {//为人员分配角色权限
			personnel = personnelService.findPersonnel(staffcode);
			rulelist = ruleService.findAllRule();
			//personnelRules = permissionService.findAllPersonneltorulelink();
		} else {
			throw new RuntimeException("a string value of rule or personnel for the param of principalType is required.");
		}
		
		return SUCCESS;
	}
	
	public String empowerForRule() throws Exception {
		rule = ruleService.findRule(ruleno);
		menulist = menuService.findAllMenuinfo();
		return SUCCESS;
	}
	
	public String empowerForPersonnel() throws Exception {
		personnel = personnelService.findPersonnel(staffcode);
		rulelist = ruleService.findAllRule();
		return SUCCESS;
	}

	/**
	 * @return the permissionService
	 */
	public PermissionService getPermissionService() {
		return permissionService;
	}

	/**
	 * @param permissionService the permissionService to set
	 */
	public void setPermissionService(PermissionService permissionService) {
		this.permissionService = permissionService;
	}

	/**
	 * @return the personnelRules
	 */
	public List<Personneltorulelink> getPersonnelRules() {
		return personnelRules;
	}

	/**
	 * @param personnelRules the personnelRules to set
	 */
	public void setPersonnelRules(List<Personneltorulelink> personnelRules) {
		this.personnelRules = personnelRules;
	}

	/**
	 * @return the principalType
	 */
	public String getPrincipalType() {
		return principalType;
	}

	/**
	 * @param principalType the principalType to set
	 */
	public void setPrincipalType(String principalType) {
		this.principalType = principalType;
	}

	/**
	 * @return the ruleMenus
	 */
	public List<Menuctrl> getRuleMenus() {
		return ruleMenus;
	}

	/**
	 * @param ruleMenus the ruleMenus to set
	 */
	public void setRuleMenus(List<Menuctrl> ruleMenus) {
		this.ruleMenus = ruleMenus;
	}

	/**
	 * @return the menulist
	 */
	public List<Menuinfo> getMenulist() {
		return menulist;
	}

	/**
	 * @param menulist the menulist to set
	 */
	public void setMenulist(List<Menuinfo> menulist) {
		this.menulist = menulist;
	}

	/**
	 * @return the menuService
	 */
	public MenuService getMenuService() {
		return menuService;
	}

	/**
	 * @param menuService the menuService to set
	 */
	public void setMenuService(MenuService menuService) {
		this.menuService = menuService;
	}

	/**
	 * @return the rulelist
	 */
	public List<Rule> getRulelist() {
		return rulelist;
	}

	/**
	 * @param rulelist the rulelist to set
	 */
	public void setRulelist(List<Rule> rulelist) {
		this.rulelist = rulelist;
	}

	/**
	 * @return the ruleService
	 */
	public RuleService getRuleService() {
		return ruleService;
	}

	/**
	 * @param ruleService the ruleService to set
	 */
	public void setRuleService(RuleService ruleService) {
		this.ruleService = ruleService;
	}

	/**
	 * @return the personnel
	 */
	public Personnel getPersonnel() {
		return personnel;
	}

	/**
	 * @param personnel the personnel to set
	 */
	public void setPersonnel(Personnel personnel) {
		this.personnel = personnel;
	}

	/**
	 * @return the rule
	 */
	public Rule getRule() {
		return rule;
	}

	/**
	 * @param rule the rule to set
	 */
	public void setRule(Rule rule) {
		this.rule = rule;
	}

	/**
	 * @return the ruleno
	 */
	public long getRuleno() {
		return ruleno;
	}

	/**
	 * @param ruleno the ruleno to set
	 */
	public void setRuleno(long ruleno) {
		this.ruleno = ruleno;
	}

	/**
	 * @return the staffcode
	 */
	public String getStaffcode() {
		return staffcode;
	}

	/**
	 * @param staffcode the staffcode to set
	 */
	public void setStaffcode(String staffcode) {
		this.staffcode = staffcode;
	}

	/**
	 * @return the personnelService
	 */
	public PersonnelService getPersonnelService() {
		return personnelService;
	}

	/**
	 * @param personnelService the personnelService to set
	 */
	public void setPersonnelService(PersonnelService personnelService) {
		this.personnelService = personnelService;
	}
	
	
}
